{template '../header'}

<div>
    找回密码
</div>
<div>
    <form method="post">
        <div>
            <label>用户名</label>
            <input type="text" id="username" name="username" placeholder="用户名" />
        </div>
        <div>
            <label>验证码</label>
            <div>
                <input type="text" autocomplete="off" id="mcode" name="valicode" placeholder="验证码">
                <button type="button" id="get_mcode">获取验证码</button>
            </div>
        </div>
        <div>
            <label>新密码</label>
            <input type="password" name="password" placeholder="输入新密码" />
        </div>
        <div>
            <button type="submit" name="do" value="recover">修改密码</button>
        </div>
    </form>
</div>

<script type="text/javascript">
    $(function () {

        //获取短信验证码
        $('#get_mcode').click(function () {

            var username = $("#username").val();

            if (!username) {
                $.toast('用户名错误');
                $("#username").focus();
                return false;
            }

            var wait = 60;
            var o = $(this);
            o.prop("disabled", true);
            o.text('发送中 ...');

            $.ajax({
                url: '/code/recover',
                method: 'get',
                dataType: 'json',
                data: {username: username},
                success: function (ret) {
                    if (ret.code == 1) {
                        var timeID = setInterval(function () {
                            o.text(wait + 's');
                            wait = wait - 1;
                            if (wait == -1) {
                                clearInterval(timeID);
                                o.text("获取验证码");
                                o.prop("disabled", false);
                            }
                        }, 1000);

                        $('#mcode').val('');
                        $.toast('验证码已发出');
                    } else {
                        o.text("获取验证码");
                        o.prop("disabled", false);
                        $.toast(ret.msg);
                    }
                },
            });
        });

    });
</script>
{template '../footer'}